package com.arnold.test.transformations

import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by arnold.zhu on 2017/7/17.
  */
object FlatMap {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("Spark01Learn")
    val sc = new SparkContext(conf)

    val a = sc.parallelize(1 to 4, 2)
    println(a)
    // 类似于map，但是每一个输入元素，会被映射为0到多个输出元素
    val b = a.flatMap(x => 1 to x)

    b.collect().foreach {
      println(_)
    }
  }

}
